﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<KLS.PPDS.Web.Models.ArticleViewModel>" %>
<%@ Import Namespace="KLS.PPDS.Resources" %>
<%@ Import Namespace="KLS.PPDS.Utility.Html" %>
<%@ Import Namespace="KLS.PPDS.Utility" %>
<%@ Import Namespace="KLS.PPDS.Utility.Html" %>
<script type="text/javascript">
//    $(document).ready(function () {
//        Shadowbox.init({
//            handleOversize: "drag",
//            modal: true
//        });
    //    });

    function RemoveAddMultipleImageButton() {
       // alert('hi');
        if ( !$.browser.msie) {
            $('.add-IE-multiple-image-button').parents().eq(1).hide();
        }
    }

    $(document).ready(function () {
        ApplyUploadify();
    });

    function ApplyUploadify() {
        //  alert('hi ApplyUploadify');
        EnablingUploadifyByCheckingFlashInstalledInBrowser();
        ApplyImageUloadify();
        ApplyTextUloadify();
    }

    function EnablingUploadifyByCheckingFlashInstalledInBrowser() {
        var hasFlash = false;
        try {
            var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
            if (fo) hasFlash = true;
        } catch (e) {
            if (navigator.mimeTypes["application/x-shockwave-flash"] != undefined) hasFlash = true;
        }
       
    //     alert(hasFlash);

        if (hasFlash) {

            $('.text-upload').hide();
            $('.image-upload').hide();
            $('.text-upload-lable').hide();
            $('.image-upload-lable').hide();
            
            $('.text-upload').each(function () {
                if (!$(this).hasClass('single-text-upload')) {
                    $(this).addClass('single-text-upload');
                }
            });

            $('.text-upload').each(function () {
                if (!$(this).hasClass('single-text-upload')) {
                    $(this).addClass('single-text-upload');
                }
            });

            $('.image-upload').each(function () {
                if (!$(this).hasClass('multiple-image-upload')) {
                    $(this).addClass('multiple-image-upload');
                }
            }); 
        }
    }

    function ApplyImageUloadify() {
        var imgResposnTxt = "";
        // alert('hi ApplyImageUloadify');

            var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
            var ASPSESSID = "<%= Session.SessionID %>";


            $(".multiple-image-upload").each(function () {
                //alert($(this).attr('ID'));

                var comId = $(this).attr('comId');
                var pubId = $(this).attr('pubId');
                var artId = $(this).attr('artId');
                var contentId = $(this).attr('contentId');
                var disabled = $(this).attr('disabled');
                var height = 16;
                if (disabled) {
                    //height = 0;
                    //$(this).hide();
                    height = 0;
                    $(this).parents().eq(2).hide();
                }

                // alert(disabled);
                if ($(this).parent().find('.uploadifyQueue').size() == 0) {//already uploadify called (if value is not 0 )

                    $(this).uploadify({
                        'hideButton': true,
                        'wmode': 'transparent',
                        'height': height,
                        //'buttonImg': '<%= Url.Content("~/Content/images/buttons/save.png") %>',
                        'uploader': '<%= Url.Content("~/Scripts/Plugins/uploadify/uploadify.swf") %>',
                        'script': '<%= Url.Action("../ArticleContent/UploadImage") %>',
                        'fileDataName': 'file',
                        'buttonText': '<%:CommonString.UploadImage %>...',
                        'multi': true,
                        'sizeLimit': '<%:Model.SizeLimit%>',
                        'simUploadLimit': 1,
                        'fileExt': '<%:Model.SupportedImageFilesExt%>',
                        'fileDesc': 'Image Files',
                        'cancelImg': '<%= Url.Content("~/Scripts/Plugins/uploadify/cancel.png") %>',
                        'auto': true,
                        'scriptData': { 'ASPSESSID': ASPSESSID, 'AUTHID': auth, 'comId': comId, 'pubId': pubId, 'artId': artId, 'contentId': contentId, 'type': 'img' },
                        'onError': function (a, b, c, d) {

                            var errMsg = '';
                            if (d.status == 404)
                            //alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
                                errMsg = "Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>";
                            else if (d.type === "HTTP")
                            //alert("error " + d.type + ": " + d.status);
                                errMsg = "error " + d.type + ": " + d.status
                            else if (d.type === "File Size")
                            //alert(c.name + " " + d.type + " Limit: " + Math.round(d.info / (1024 * 1024)) + "MB");
                                errMsg = c.name + " " + d.type + " Limit: " + Math.round(d.info / (1024 * 1024)) + "MB";
                            else
                            //alert("error " + d.type + ": " + d.text);
                                errMsg = "error " + d.type + ": " + d.text;

                            if (errMsg != '') {
                                ShowError(errMsg);
                            }

                        },

                        'onComplete': function (event, queueId, fileObj, response, data) {
                            if (response != "") {
                                imgResposnTxt = response;
                            }
                        },
                        'onAllComplete': function (event, data) {

                            var msg = data.filesUploaded + ' files uploaded successfully!';
                            var action = '/ArticleContent/LoadImageContent?contentId=' + imgResposnTxt;
                            var target = $('#img_thumbs_' + imgResposnTxt);
                            //AjaxCall(action, target);
                            AjaxCallWithAfterSucessCallback(action, target, NaN, ApplyUploadify);

                        }

                    });
                }
            }); 
    }


    function ApplyTextUloadify() {
        var imgResposnTxt = "";
        var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
        var ASPSESSID = "<%= Session.SessionID %>";

      //  alert('hi ApplyTextUloadify');
        $(".single-text-upload").each(function () {
            //alert($(this).attr('ID'));

            var comId = $(this).attr('comId');
            var pubId = $(this).attr('pubId');
            var artId = $(this).attr('artId');
            var contentId = $(this).attr('contentId');
            var disabled = $(this).attr('disabled');
            var height = 16;
            if (disabled) {
                height = 0;
                $(this).parents().eq(2).hide();
                // $(this).parents().find('object').hide();
                //alert(disabled);
                //$(this).parent().hide();
                //$(this).parents().eq(2).css('background-color','red');
                //alert('hi');
            }
            if ($(this).parent().find('.uploadifyQueue').size() == 0) { //already uploadify called (if value is not 0 )

                $(this).uploadify({
                    'hideButton': true,
                    'wmode': 'transparent',
                    'height': height,
                    'uploader': '<%= Url.Content("~/Scripts/Plugins/uploadify/uploadify.swf") %>',
                    'script': '<%= Url.Action("../ArticleContent/UploadText") %>',
                    'fileDataName': 'file',
                    'buttonText': '<%:CommonString.UploadText%>...',
                    'multi': false,
                    'sizeLimit': '<%:Model.SizeLimit%>',
                    'simUploadLimit': 1,
                    'fileExt': '<%:Model.SupportedTextFilesExt%>',
                    'fileDesc': 'Text Files',
                    'cancelImg': '<%= Url.Content("~/Scripts/Plugins/uploadify/cancel.png") %>',
                    'auto': true,
                    'scriptData': { 'ASPSESSID': ASPSESSID, 'AUTHID': auth, 'comId': comId, 'pubId': pubId, 'artId': artId, 'contentId': contentId, 'type': 'txt' },
                    'onError': function (a, b, c, d) {

                        var errMsg = '';
                        if (d.status == 404)
                        //alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
                            errMsg = "Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>";
                        else if (d.type === "HTTP")
                        //alert("error " + d.type + ": " + d.status);
                            errMsg = "error " + d.type + ": " + d.status
                        else if (d.type === "File Size")
                        //alert(c.name + " " + d.type + " Limit: " + Math.round(d.info / (1024 * 1024)) + "MB");
                            errMsg = c.name + " " + d.type + " Limit: " + Math.round(d.info / (1024 * 1024)) + "MB";
                        else
                        //alert("error " + d.type + ": " + d.text);
                            errMsg = "error " + d.type + ": " + d.text;

                        if (errMsg != '') {
                            ShowError(errMsg);
                        }

                    },

                    'onComplete': function (event, queueId, fileObj, response, data) {

                        if (response != "") {

                            imgResposnTxt = response;
                            // var msg = data.filesUploaded + ' files uploaded successfully!';
                            var action = '/ArticleContent/LoadTextContent?contentId=' + imgResposnTxt;
                            var target = $("div#articleContent_" + imgResposnTxt);

                            // AjaxCall(action, target);
                            AjaxCallWithAfterSucessCallback(action, target, NaN, ApplyUploadify);
                        }
                    },
                    'onAllComplete': function (event, data) {

                        //                    var msg = data.filesUploaded + ' files uploaded successfully!';
                        //                    var action = '/ArticleContent/LoadTextContent?contentId=' + resposnTxt;
                        //                    var target = $("#txt_thumbs_" + imgResposnTxt);
                        //                    alert(action + target);
                        //                    AjaxCall(action, target);

                    }

                });
            }
        });
    }


    //RemoveAddMultipleImageButton();
</script>

<br />
<div class="article-head">     
     <%Html.RenderPartial("PublicationTitle",Model.Publication); %>
</div>
<br />
<div class="article-main-content">


    <%using (Html.BeginForm("SaveArticle", "Article", FormMethod.Post, new { @Id = "article-form", @onkeypress = "ApplyArticleEnter(event,'div#ArticleMainSubmitButton');" }))
      {
          %>
     
    <%:Html.HiddenFor(model => model.Article.Id)%>
   
    
    <%: Html.HiddenFor(model => model.Article.CreatedDate) %>
  
    
    <%: Html.HiddenFor(model => model.Article.CreatedBy)%>
   

    <%: Html.HiddenFor(model => model.Article.UpdatedBy)%>
 

    <%: Html.HiddenFor(model => model.Article.UpdatedDate)%>
   

    <%: Html.HiddenFor(model => model.Article.IsDeleted)%>
  

    <%: Html.HiddenFor(model => model.OldIsReadyForEditor)%>


    <%: Html.HiddenFor(model => model.OldIsReadyForGraphic)%>

    <%: Html.HiddenFor(model => model.PerviousPublicationId)%>
 

    <table>

        <tr>
            <td>
                <%:CommonString.Headline %>
            </td>
            <td>
                <%  var headline = Model.IsTextDisable.Equals(false) ? (object)new { @maxlength = "150", @class = "required" } : (object)new { @maxlength = "150", @class = "required", @disabled = "disabled" };%>
                <%:Html.TextBoxFor(x => x.Article.Headline, (object)headline )%>
            </td>
        </tr>
        <tr>
            <td>
                <%:CommonString.Comments %>
            </td>
            <td>
                <%  var com = Model.IsTextDisable.Equals(false) ? (object)new { @rows = "4", @cols = "28", @maxlength = "2000" } : (object)new { @rows = "4", @cols = "28", @maxlength = "2000", @disabled = "disabled" };%>
                <%:Html.TextAreaFor(x => x.Article.Comments, (object)com)%>
            </td>
        </tr>
        <tr>
            <td>
                <%:CommonString.Publication %>
            </td>
            <td>
                <%  var pub = Model.IsTextDisable.Equals(false) ? (object)new { @class = "required" } : (object)new { @class = "required", @disabled = "disabled" };%>
                <%:Html.DropDownListFor(x => x.Article.PublicationId, Model.PublicationList, (object)pub)%>
            </td>
            
        </tr>
        <tr>
            <td>
                <%:CommonString.Extent %>
            </td>
            <td>
                <%  var ext = Model.IsTextDisable.Equals(false) ? (object)new { @class = "extension", } : (object)new { @class = "extension", @disabled = "disabled" };%>
                
                <%:Html.DropDownListFor(x => x.Extent1, Model.Extend1List, CommonMessage.PleaseSelect, (object)ext)%>
                -
                <%:Html.DropDownListFor(x => x.Extent2, Model.Extend2List, CommonMessage.PleaseSelect, (object)ext)%>
            </td>
        </tr>
        <tr>
            <td>
                <%:CommonString.StartPage %>
            </td>
            <td>
                <%  var strtPage = Model.IsTextDisable.Equals(false) ? (object)new { } : (object)new { @class = "required", @disabled = "disabled" };%>
                <%--<%  var strtPage = Model.IsTextDisable.Equals(false) ? (object)new { } : (object)new { @class = "required" };%>--%>
                <%:Html.DropDownListFor(x => x.StartPage, Model.StartPageList, CommonString.Standby, (object)strtPage)%>
            </td>
        </tr>
        <tr>
            <td>
              <%--  <% 
                    var ediotr = (object)new { @type = "CheckBox", @class = "checkbox" };

                    if (Model.IsDisable.Equals(true) && Model.Article.IsReadyForEditor.Equals(false))
                    {
                        ediotr = (object)new { @type = "CheckBox", @class = "checkbox", @disabled = "disabled" };
                    }
                    else if (Model.Article.IsReadyForEditor.Equals(true))
                    {
                        ediotr = (object)new { @type = "CheckBox", @class = "checkbox", @disabled = "disabled", @checked = "checked" };
                    }
           
                    //var ediotr = Model.IsDisable.Equals(false) ? (object)new { @type = "CheckBox", @class = "checkbox" } : (object)new { @type = "CheckBox", @class = "checkbox", @disabled = "disabled", @checked = "checked" };%>
                <%--<%:Html.TextBoxFor(x => x.Article.IsReadyForEditor, (object)ediotr)%>--%>
                
                <%
                    var eChecked = string.Empty;
                    var eDisabled = string.Empty;
                    if (Model.Article.IsReadyForEditor.Equals(true)) 
                    {
                        eChecked = "checked";
                    }
                    if (Model.ReadyForEditorPermission.Equals(false) || Model.IsTextDisable.Equals(true)) 
                    {
                        eDisabled = "disabled";
                    }
               %>

                <input name="Article.IsReadyForEditor" class="checkbox chk-editor" id="Article_IsReadyForEditor" type="checkbox" value="False" <%:eChecked %> <%:eDisabled %>/><%:CommonString.ReadyForEditing %>
            </td>
            <td>
               <div style="display: table-cell">(</div><%:Html.DivActionLink(CommonString.MailToEditor, "", new { @class = "email-button", @onclick = "" })%><div style="display: table-cell">)</div>
            </td>
        </tr>
        <tr>
            <td>
               <%-- <%  
                    var graphics = (object)new { @type = "CheckBox", @class = "checkbox" };

                    if (Model.IsDisable.Equals(true) && Model.Article.IsReadyForGraphic.Equals(false)) 
                    {
                        graphics = (object)new { @type = "CheckBox", @class = "checkbox", @disabled = "disabled" };
                    }
                    else if ( Model.Article.IsReadyForGraphic.Equals(true)) 
                    {
                        graphics = (object)new { @type = "CheckBox", @class = "checkbox", @disabled = "disabled", @checked = "checked" };
                    }
          
                    //var graphics = Model.IsDisable.Equals(false)  ? (object)new { @type = "CheckBox", @class = "checkbox" } : (object)new { @type = "CheckBox", @class = "checkbox", @disabled = "disabled", @checked = "checked" };
                %>
                <%:Html.TextBoxFor(x => x.Article.IsReadyForGraphic, (object)graphics)%><%:CommonString.ReadyForLayout %>--%>

                <%
                    var gChecked = string.Empty;
                    var gDisabled = string.Empty;
                    if (Model.Article.IsReadyForGraphic.Equals(true)) 
                    {
                        gChecked = "checked";
                    }
                    if (Model.ReadyForGraphicsPermission.Equals(false)) 
                    {
                        gDisabled = "disabled";
                    }
               %>
               <input name="Article.IsReadyForGraphic" class="checkbox chk-graphic" id="Article_IsReadyForGraphic" type="checkbox" value="False" <%:gChecked %> <%:gDisabled %>/><%:CommonString.ReadyForLayout %>
            </td>
            <td>
               <div style="display: table-cell">(</div><%:Html.DivActionLink(CommonString.MailToGraphicDesigner, "", new { @class = "email-button", @onclick = "" })%><div style="display: table-cell">)</div>
            </td>
        </tr>
        <tr>
            <td>
            </td>
              <%if (Model.IsGraphicsDisable.Equals(false)) 
              { %>
                <td>
                       
                            <%if (Model.Article.Id > 0) 
                              {%>
                               
                                    <%:Html.DivActionLink(CommonString.New, "", new { @class = "add-new-button", @target = "div#article-page", @href = string.Format("Article/Index?publicationId={0}&articleId={1}", Model.Publication.Id, 0), @message = CommonMessage.DeleteConfirmation })%>
                               
                                
                                <% if (Model.IsTextDisable.Equals(false) && CommonSession.IsUserJournalist.Equals(false))
                                {%>                                                               
                                    
                                      <%:Html.DivActionLink(CommonString.Delete, "", new { @class = "delete-centre-button", @target = "div#article-page", @href = string.Format("Article/Delete?publicationId={0}&articleId={1}", Model.Publication.Id, Model.Article.Id), @message = CommonMessage.DeleteConfirmation })%>
                                   
                                <%}%> 

                              <%
                              }%>

                            <% if (Model.IsTextDisable.Equals(false))
                            {%>
                               
                                    <%:Html.DivActionLink(CommonString.Save, "", new { @ID = "ArticleMainSubmitButton", @class = "save-button", @onclick = "AjaxPostArticle();", @message = CommonMessage.ConfirmationReadyForLayout })%>                        
                               
                            <%
                            }%>
                </td>
              <% 
              } %>
        </tr>

    </table>
 
</div>
<%}%>

    <div class="article-sub-content">
    

            <% if (Model.ListArticleContent != null && Model.ListArticleContent.Count > 0) 
        {
            foreach (var item in Model.GetArticleContentViewModelList())
            {
                Html.RenderPartial(@"~/Views/Article/ArticleContent.ascx", item);             
            }
        } %>


    </div>     
        <%
                var someCondition = true;
                if (Model.Article.Id > 0 && someCondition)
                { %>
                <hr />
            <%
                Html.RenderPartial(@"~/Views/Article/AddSubArticleButton.ascx", Model);    
            %>

        <% 
        } %>